#include <iostream>
#include <string>
#include <vector>
using namespace std;

string getComSubstr(string &str1,string &str2)
{
    if(str1.size() > str2.size())
        swap(str1,str2);

        int len1 = str1.size();
        int len2 = str2.size();

        int start = 0,max_size = 0;

        vector<vector<int>> MSC(len1+1 ,vector<int>(len2+1 , 0));
        for(int i = 1;i < len1;++i)
        {
            for(int j = 1;j < len2;++j)
            {
                if(str2[j - 1] == str1[i - 1])
                    MSC[i][j] = MSC[i - 1][j - 1] + 1;

                if(MSC[i][j] > max_size)
                {
                    max_size = MSC[i][j];
                    start = i - max_size;
                }
            }
        }
        return str1.substr(start,max_size);
}

int main()
{
     string str1,str2;
     while(cin >> str1 >> str2)
     {
         string substr = getComSubstr(str1,str2);
         cout << substr << endl;
     }
     return 0;
}
